from selenium.webdriver.common.by import By
from page.BasePage import BasePage

class WebPage(BasePage):
    # driver.find_element(By.XPATH, "//i[text()='close']").click()
    close_page_i=(By.XPATH, "//i[text()='close']")
    # driver.find_element(By.XPATH, "//i[text()='translate']").click()
    language_translate_click_i=(By.XPATH, "//i[text()='translate']")
    # driver.find_element(By.XPATH, "//div[text()='中文简体']").click()
    language_click_handoff_div=(By.XPATH, "//div[text()='%s']")
    # driver.find_element(By.XPATH, "//span[text()='登入']").click()
    login_page_click_span=(By.XPATH, "//span[text()='登入']")
    # driver.find_element(By.XPATH, "//*[contains(text(), '管理员登入')]").click()
    admin_login_click_text=(By.XPATH, "//*[contains(text(), '管理员登入')]")
    # driver.find_element(By.XPATH, "//div[text()='管理员'] /../../../..").send_keys(name)
    admin_user_sendkeys_div=(By.XPATH, "//div[text()='管理员'] /../../../..")
    # driver.find_element(By.XPATH, "//div[text()='密码'] /../../../..").send_keys(password)
    admin_password_sendkeys_div=(By.XPATH, "//div[text()='密码'] /../../../..")
    # driver.find_element(By.XPATH, "//body/div[3]/div[2]/div/div[3]/button/span[2]/span").click()
    start_click_login_body=(By.XPATH, "//body/div[3]/div[2]/div/div[3]/button/span[2]/span")
    assert_message_div=(By.XPATH, "//div[contains(@class, 'q-notification__message')]")

    #关闭页面
    def close_page(self):
        self.find_element(self.close_page_i).click()
    #切换语言
    def language_translate(self,language):
        self.find_element(self.language_translate_click_i).click()

        temp=list(self.language_click_handoff_div)
        temp[1]=temp[1] % language
        self.find_element(tuple(temp)).click()
    # 输入账号密码
    def user_login(self,username,password):
        self.find_element(self.login_page_click_span).click()
        self.find_element(self.admin_login_click_text).click()
        self.find_element(self.admin_user_sendkeys_div).send_keys(username)
        self.find_element(self.admin_password_sendkeys_div).send_keys(password)
        self.find_element(self.start_click_login_body).click()

    def  start_login(self):
        return self.find_element(self.assert_message_div).text()


